//==========================================================
// 此代码由TilverNET代码生成工具自动生成，请不要修改
// 代码生成器版本号：1.2
// 作者：landy
// 联系方式：(QQ)86566178
// 创建时间：2014/6/21 10:58:22
//==========================================================

using System;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using System.Linq;
using Tilver.Data;
using Tilver.Data.DataPager;

namespace Weixin.MP.DAL.WeixinMP
{
	#region EO

	/// <summary>
	/// 操作日志 《dbo.OperateLog(实体类)》
	/// </summary>
	[Serializable]
	public class OperateLogEO : IRowMapper<OperateLogEO>
	{
		protected bool _hasOriginal = false;
		protected int _logId;
		protected int _originalLogId;
		protected string _userId;
		protected string _clientIp;
		protected OperateLogEO.LogTypeEnum? _logType;
		protected string _content;
		protected DateTime? _logDate;

		/// <summary>
		/// 主键是否有原始值（即数据库中保存的值），用于实体对象更新时
		/// </summary>
		public bool HasOriginal
		{
			get { return _hasOriginal; }
		}


		/// <summary>
		/// 日志ID 《[主键]  [int]   自增字段》
		/// </summary>
		public int LogId
		{
			get { return _logId; }
			set { _logId = value;}
		}

		/// <summary>
		/// 日志ID 《数据库中的原始主键值副本》
		/// </summary>
		public int OriginalLogId
		{
			get { return _originalLogId; }
			set { 
				_hasOriginal = true;
				_originalLogId = value;
			}
		}

		/// <summary>
		/// 操作用户 《[字段]  [varchar]》
		/// </summary>
		public string UserId
		{
			get { return _userId; }
			set { _userId = value;}
		}

		/// <summary>
		/// 客户端IP 《[字段]  [varchar]》
		/// </summary>
		public string ClientIp
		{
			get { return _clientIp; }
			set { _clientIp = value;}
		}

		/// <summary>
		/// 日志类型 《[字段]  [tinyint]》
		/// </summary>
		/// <remarks>
		///    Login-1-登录
		///    Insert-2-添加
		///    Delete-3-删除
		///    Edit-4-修改
		///    Other-5-其他
		/// </remarks>
		public OperateLogEO.LogTypeEnum? LogType
		{
			get { return _logType; }
			set { _logType = value;}
		}

		/// <summary>
		/// 操作内容 《[字段]  [nvarchar]》
		/// </summary>
		public string Content
		{
			get { return _content; }
			set { _content = value;}
		}

		/// <summary>
		/// 日志时间 《[字段]  [datetime]》
		/// </summary>
		public DateTime? LogDate
		{
			get { return _logDate; }
			set { _logDate = value;}
		}

		/// <summary>
		/// 默认构造函数
		/// </summary>
		public OperateLogEO() 
		{
			LogType = (OperateLogEO.LogTypeEnum?)1;
			LogDate = DateTime.Now;
		}

		/// <summary>
		/// 自定义构造函数
		/// </summary>
		/// <param name = "logId">日志ID</param>
		/// <param name = "userId">操作用户</param>
		/// <param name = "clientIp">客户端IP</param>
		/// <param name = "logType">
		/// 日志类型
		///    Login-1-登录
		///    Insert-2-添加
		///    Delete-3-删除
		///    Edit-4-修改
		///    Other-5-其他
		/// </param>
		/// <param name = "content">操作内容</param>
		/// <param name = "logDate">日志时间</param>
		public OperateLogEO(int logId, string userId, string clientIp, OperateLogEO.LogTypeEnum? logType, string content, DateTime? logDate) 
		{
			_logId = logId;
			_userId = userId;
			_clientIp = clientIp;
			_logType = logType;
			_content = content;
			_logDate = logDate;
		}


		/// <summary>
		/// 将结果集映射成实体对象
		/// </summary>
		/// <param name = "reader">只进结果集流</param>
		/// <return></return>
		public OperateLogEO MapRow(IDataReader reader)
		{
			var ret = new OperateLogEO();
			ret.LogId = (int)reader["LogId"];
			ret.OriginalLogId = ret.LogId;
			ret.UserId = (reader["UserId"] is DBNull) ? null : (string)reader["UserId"];
			ret.ClientIp = (reader["ClientIp"] is DBNull) ? null : (string)reader["ClientIp"];

			if (reader["LogType"] is DBNull)
				ret.LogType = null;
			else
				ret.LogType = (OperateLogEO.LogTypeEnum?)reader["LogType"];
			ret.Content = (reader["Content"] is DBNull) ? null : (string)reader["Content"];
			ret.LogDate = (reader["LogDate"] is DBNull) ? null : (DateTime?)reader["LogDate"];
			return ret;
		}

		/// <summary>
		/// 将结果集映射成实体对象，返回映射方法
		/// </summary>
		/// <return></return>
		public Func<IDataReader, OperateLogEO> GetMapper()
		{
			return MapRow;
		}


		/// <summary>
		/// 日志类型
		/// </summary>
		/// <remarks>
		///    Login-1-登录
		///    Insert-2-添加
		///    Delete-3-删除
		///    Edit-4-修改
		///    Other-5-其他
		/// </remarks>
		public enum LogTypeEnum : byte
		{
			/// <summary>
			/// 登录
			/// </summary>
			Login = 1,

			/// <summary>
			/// 添加
			/// </summary>
			Insert = 2,

			/// <summary>
			/// 删除
			/// </summary>
			Delete = 3,

			/// <summary>
			/// 修改
			/// </summary>
			Edit = 4,

			/// <summary>
			/// 其他
			/// </summary>
			Other = 5,

		}

	}


	#endregion
	#region MO

	/// <summary>
	/// 操作日志 《dbo.OperateLog(逻辑类)》
	/// </summary>
	public class OperateLogMO : DbManagerBase
	{

		#region 构造函数
		/// <summary>
		/// 构造函数
		/// </summary>
		/// <param name = "routeData">路由数据</param>
		public OperateLogMO(object routeData = null) : base(routeData) { }

		/// <summary>
		/// 构造函数
		/// </summary>
		/// <param name = "connectionStringName">连接字符串名称</param>
		public OperateLogMO(string connectionStringName) : base(connectionStringName) { }

		#endregion

		#region 私有方法
		/// <summary>
		/// 数据库访问操作方法
		/// </summary>
		/// <param name = "sql">SQL语句</param>
		/// <return>返回数据操作对象</return>
		private DbAdoBase AdoBase(string sql)
		{
			return DataBase.CreateDbAdo(sql, CommandType.Text);
		}

		#endregion

		#region Select方法集合
		/// <summary>
		/// 按主键查询
		/// </summary>
		/// <param name = "logId">日志ID</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public OperateLogEO SelectByPK(int logId, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			sql.AppendFormat(@"SELECT [LogId], [UserId], [ClientIp], [LogType], [Content], [LogDate] FROM [dbo].[OperateLog] WHERE [LogId]=@LogId ");
			return AdoBase(sql.ToString())
							.AddInParameter("@LogId", logId, DbType.Int32, 4)
							.ExecuteReader(tm).MapToSingle(new OperateLogEO().GetMapper());
		}


		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "logId">日志ID</param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<OperateLogEO> SelectByLogId(int logId, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [LogId], [UserId], [ClientIp], [LogType], [Content], [LogDate] FROM [dbo].[OperateLog] WHERE [LogId]=@LogId");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter("@LogId", logId, DbType.Int32, 4)
							.ExecuteList(new OperateLogEO().GetMapper(), tm);
		}
		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "userId">操作用户</param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<OperateLogEO> SelectByUserId(string userId, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [LogId], [UserId], [ClientIp], [LogType], [Content], [LogDate] FROM [dbo].[OperateLog] WHERE [UserId]=@UserId");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter("@UserId", userId, DbType.AnsiString, 20)
							.ExecuteList(new OperateLogEO().GetMapper(), tm);
		}
		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "clientIp">客户端IP</param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<OperateLogEO> SelectByClientIp(string clientIp, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [LogId], [UserId], [ClientIp], [LogType], [Content], [LogDate] FROM [dbo].[OperateLog] WHERE [ClientIp]=@ClientIp");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter("@ClientIp", clientIp, DbType.AnsiString, 50)
							.ExecuteList(new OperateLogEO().GetMapper(), tm);
		}
		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "logType">
		/// 日志类型
		///    Login-1-登录
		///    Insert-2-添加
		///    Delete-3-删除
		///    Edit-4-修改
		///    Other-5-其他
		/// </param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<OperateLogEO> SelectByLogType(OperateLogEO.LogTypeEnum? logType, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [LogId], [UserId], [ClientIp], [LogType], [Content], [LogDate] FROM [dbo].[OperateLog] WHERE [LogType]=@LogType");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter("@LogType", logType, DbType.Byte, 1)
							.ExecuteList(new OperateLogEO().GetMapper(), tm);
		}
		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "content">操作内容</param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<OperateLogEO> SelectByContent(string content, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [LogId], [UserId], [ClientIp], [LogType], [Content], [LogDate] FROM [dbo].[OperateLog] WHERE [Content]=@Content");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter("@Content", content, DbType.String, -1)
							.ExecuteList(new OperateLogEO().GetMapper(), tm);
		}
		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "logDate">日志时间</param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<OperateLogEO> SelectByLogDate(DateTime? logDate, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [LogId], [UserId], [ClientIp], [LogType], [Content], [LogDate] FROM [dbo].[OperateLog] WHERE [LogDate]=@LogDate");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter("@LogDate", logDate, DbType.DateTime, 8)
							.ExecuteList(new OperateLogEO().GetMapper(), tm);
		}

		/// <summary>
		/// 按自定义条件查询
		/// </summary>
		/// <param name = "where">自定义条件,where子句</param>
		/// <param name = "top">获取行数</param>
		/// <param name = "sort">排序表达式</param>
		/// <param name = "paras">where子句中定义的参数集合</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<OperateLogEO> Select(string where, int top, string sort, IEnumerable<DbParameter> paras, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [LogId], [UserId], [ClientIp], [LogType], [Content], [LogDate] FROM [dbo].[OperateLog] ");
			if (!string.IsNullOrEmpty(where)) format.AppendFormat(" WHERE {0} ", where);
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddParameters(paras)
							.ExecuteList(new OperateLogEO().GetMapper(), tm);
		}

		/// <summary>
		/// 分页查询
		/// </summary>
		/// <param name = "where">条件表达式</param>
		/// <param name = "sort">排序表达式</param>
		/// <param name = "paras">传入参数</param>
		/// <param name = "pageSize">页大小</param>
		/// <param name = "pageIndex">页码</param>
		/// <param name = "recordCount">总记录数，由于计算总记录数影响数据库性能，只有小于或等于0的情况下才返回总记录数</param>
		/// <return>分页数据</return>
		public List<OperateLogEO> SelectPager(string where, string sort, IList<DbParameter> paras, long pageSize, long pageIndex, ref long recordCount)
		{
			var sql = new StringBuilder();
			sql.AppendFormat(@"SELECT [LogId], [UserId], [ClientIp], [LogType], [Content], [LogDate] FROM [dbo].[OperateLog]");
			if (!string.IsNullOrEmpty(where)) sql.AppendFormat(" WHERE {0} ", where);
			if (!string.IsNullOrEmpty(sort)) sql.AppendFormat(" ORDER BY {0} ", sort);
			var pager = this.DataBase.CreatePager(sql.ToString(), pageSize, "LogId");
			pager.AddParameters(paras);
			if (recordCount <= 0)
			{
				recordCount = pager.GetRecordCount();
			}
			return pager.GetPageData(pageIndex).MapToList(new OperateLogEO().GetMapper());
		}

		#endregion

		#region Insert方法集合
		/// <summary>
		/// 插入数据，有自增列时，item中自增字段为新增值，否则，返回影响的行数
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "item">要插入的实体对象</param>
		/// <return></return>
		public int Insert(OperateLogEO item, TransactionManager tm = null)
		{
			const string sql = @"INSERT INTO [dbo].[OperateLog] ([UserId], [ClientIp], [LogType], [Content], [LogDate]) VALUES (@UserId, @ClientIp, @LogType, @Content, @LogDate) ;SELECT SCOPE_IDENTITY();";
			item.LogId = int.Parse(AdoBase(sql)
												.AddInParameter("@UserId", item.UserId != null ?  (object)item.UserId : DBNull.Value, DbType.AnsiString, 20)
												.AddInParameter("@ClientIp", item.ClientIp != null ?  (object)item.ClientIp : DBNull.Value, DbType.AnsiString, 50)
												.AddInParameter("@LogType", item.LogType.HasValue ? (object)item.LogType.Value : DBNull.Value, DbType.Byte, 1)
												.AddInParameter("@Content", item.Content != null ?  (object)item.Content : DBNull.Value, DbType.String, -1)
												.AddInParameter("@LogDate", item.LogDate.HasValue ? (object)item.LogDate.Value : DBNull.Value, DbType.DateTime, 8)
												.ExecuteScalar(tm).ToString());
			return 1;
		}
		#endregion

		#region Update方法集合
		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "item">要更新的实体对象</param>
		/// <param name = "tm">事务管理对象</param>
		/// <return></return>
		public int Update(OperateLogEO item, TransactionManager tm = null)
		{
			const string sql = @"UPDATE [dbo].[OperateLog] SET [UserId]=@UserId, [ClientIp]=@ClientIp, [LogType]=@LogType, [Content]=@Content, [LogDate]=@LogDate WHERE [LogId]=@OriginalLogId";
			return AdoBase(sql)
							.AddInParameter("@OriginalLogId", (item.HasOriginal) ? item.OriginalLogId : item.LogId, DbType.Int32, 4)
							.AddInParameter("@UserId", item.UserId != null ?  (object)item.UserId : DBNull.Value, DbType.AnsiString, 20)
							.AddInParameter("@ClientIp", item.ClientIp != null ?  (object)item.ClientIp : DBNull.Value, DbType.AnsiString, 50)
							.AddInParameter("@LogType", item.LogType.HasValue ? (object)item.LogType.Value : DBNull.Value, DbType.Byte, 1)
							.AddInParameter("@Content", item.Content != null ?  (object)item.Content : DBNull.Value, DbType.String, -1)
							.AddInParameter("@LogDate", item.LogDate.HasValue ? (object)item.LogDate.Value : DBNull.Value, DbType.DateTime, 8)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "logId">日志ID</param>
		/// <param name = "userId">操作用户</param>
		/// <return></return>
		public virtual int UpdateUserId(int logId, string userId)
		{
			return UpdateUserId(logId, userId, null);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "tm">事务管理对象</param>
		/// <param name = "logId">日志ID</param>
		/// <param name = "userId">操作用户</param>
		/// <return></return>
		public virtual int UpdateUserId(int logId, string userId, TransactionManager tm = null)
		{
			const string sql = @"UPDATE [dbo].[OperateLog] SET [UserId]=@UserId  WHERE [LogId]=@LogId";
			return AdoBase(sql)
							.AddInParameter("@UserId", userId != null ?  (object)userId : DBNull.Value, DbType.AnsiString, 20)
							.AddInParameter("@LogId", logId, DbType.Int32, 4)
							.ExecuteNonQuery(tm);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "logId">日志ID</param>
		/// <param name = "clientIp">客户端IP</param>
		/// <return></return>
		public virtual int UpdateClientIp(int logId, string clientIp)
		{
			return UpdateClientIp(logId, clientIp, null);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "tm">事务管理对象</param>
		/// <param name = "logId">日志ID</param>
		/// <param name = "clientIp">客户端IP</param>
		/// <return></return>
		public virtual int UpdateClientIp(int logId, string clientIp, TransactionManager tm = null)
		{
			const string sql = @"UPDATE [dbo].[OperateLog] SET [ClientIp]=@ClientIp  WHERE [LogId]=@LogId";
			return AdoBase(sql)
							.AddInParameter("@ClientIp", clientIp != null ?  (object)clientIp : DBNull.Value, DbType.AnsiString, 50)
							.AddInParameter("@LogId", logId, DbType.Int32, 4)
							.ExecuteNonQuery(tm);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "logId">日志ID</param>
		/// <param name = "logType">
		/// 日志类型
		///    Login-1-登录
		///    Insert-2-添加
		///    Delete-3-删除
		///    Edit-4-修改
		///    Other-5-其他
		/// </param>
		/// <return></return>
		public virtual int UpdateLogType(int logId, OperateLogEO.LogTypeEnum? logType)
		{
			return UpdateLogType(logId, logType, null);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "tm">事务管理对象</param>
		/// <param name = "logId">日志ID</param>
		/// <param name = "logType">
		/// 日志类型
		///    Login-1-登录
		///    Insert-2-添加
		///    Delete-3-删除
		///    Edit-4-修改
		///    Other-5-其他
		/// </param>
		/// <return></return>
		public virtual int UpdateLogType(int logId, OperateLogEO.LogTypeEnum? logType, TransactionManager tm = null)
		{
			const string sql = @"UPDATE [dbo].[OperateLog] SET [LogType]=@LogType  WHERE [LogId]=@LogId";
			return AdoBase(sql)
							.AddInParameter("@LogType", logType.HasValue ? (object)logType.Value : DBNull.Value, DbType.Byte, 1)
							.AddInParameter("@LogId", logId, DbType.Int32, 4)
							.ExecuteNonQuery(tm);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "logId">日志ID</param>
		/// <param name = "content">操作内容</param>
		/// <return></return>
		public virtual int UpdateContent(int logId, string content)
		{
			return UpdateContent(logId, content, null);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "tm">事务管理对象</param>
		/// <param name = "logId">日志ID</param>
		/// <param name = "content">操作内容</param>
		/// <return></return>
		public virtual int UpdateContent(int logId, string content, TransactionManager tm = null)
		{
			const string sql = @"UPDATE [dbo].[OperateLog] SET [Content]=@Content  WHERE [LogId]=@LogId";
			return AdoBase(sql)
							.AddInParameter("@Content", content != null ?  (object)content : DBNull.Value, DbType.String, -1)
							.AddInParameter("@LogId", logId, DbType.Int32, 4)
							.ExecuteNonQuery(tm);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "logId">日志ID</param>
		/// <param name = "logDate">日志时间</param>
		/// <return></return>
		public virtual int UpdateLogDate(int logId, DateTime? logDate)
		{
			return UpdateLogDate(logId, logDate, null);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "tm">事务管理对象</param>
		/// <param name = "logId">日志ID</param>
		/// <param name = "logDate">日志时间</param>
		/// <return></return>
		public virtual int UpdateLogDate(int logId, DateTime? logDate, TransactionManager tm = null)
		{
			const string sql = @"UPDATE [dbo].[OperateLog] SET [LogDate]=@LogDate  WHERE [LogId]=@LogId";
			return AdoBase(sql)
							.AddInParameter("@LogDate", logDate.HasValue ? (object)logDate.Value : DBNull.Value, DbType.DateTime, 8)
							.AddInParameter("@LogId", logId, DbType.Int32, 4)
							.ExecuteNonQuery(tm);
		}

		/// <summary>
		/// 按自定义条件更新数据
		/// </summary>
		/// <param name = "set">更新列</param>
		/// <param name = "where">更新条件</param>
		/// <param name = "paras">参数集合</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public int Update(string set, string where, IEnumerable<DbParameter> paras, TransactionManager tm = null)
		{
			if (string.IsNullOrEmpty(set)) throw new ArgumentNullException("set");
			var sql = string.Format(@"UPDATE [dbo].[OperateLog] SET {0} {1}", set, (string.IsNullOrEmpty(where) ? string.Empty : " WHERE " + where));
			return AdoBase(sql)
							.AddParameters(paras)
							.ExecuteNonQuery(tm);
		}
		#endregion

		#region Delete方法集合
		/// <summary>
		/// 按主键删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "logId">日志ID</param>
		public int DeleteByPK(int logId, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM [dbo].[OperateLog] WHERE [LogId]=@LogId";
			return AdoBase(sql)
							.AddInParameter("@LogId", logId, DbType.Int32, 4)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 按字段删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "userId">操作用户</param>
		public int DeleteByUserId(string userId, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM [dbo].[OperateLog] WHERE [UserId]=@UserId";
			return AdoBase(sql)
							.AddInParameter("@UserId", userId != null ?  (object)userId : DBNull.Value, DbType.AnsiString, 20)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 按字段删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "clientIp">客户端IP</param>
		public int DeleteByClientIp(string clientIp, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM [dbo].[OperateLog] WHERE [ClientIp]=@ClientIp";
			return AdoBase(sql)
							.AddInParameter("@ClientIp", clientIp != null ?  (object)clientIp : DBNull.Value, DbType.AnsiString, 50)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 按字段删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "logType">
		/// 日志类型
		///    Login-1-登录
		///    Insert-2-添加
		///    Delete-3-删除
		///    Edit-4-修改
		///    Other-5-其他
		/// </param>
		public int DeleteByLogType(OperateLogEO.LogTypeEnum? logType, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM [dbo].[OperateLog] WHERE [LogType]=@LogType";
			return AdoBase(sql)
							.AddInParameter("@LogType", logType.HasValue ? (object)logType.Value : DBNull.Value, DbType.Byte, 1)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 按字段删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "content">操作内容</param>
		public int DeleteByContent(string content, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM [dbo].[OperateLog] WHERE [Content]=@Content";
			return AdoBase(sql)
							.AddInParameter("@Content", content != null ?  (object)content : DBNull.Value, DbType.String, -1)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 按字段删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "logDate">日志时间</param>
		public int DeleteByLogDate(DateTime? logDate, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM [dbo].[OperateLog] WHERE [LogDate]=@LogDate";
			return AdoBase(sql)
							.AddInParameter("@LogDate", logDate.HasValue ? (object)logDate.Value : DBNull.Value, DbType.DateTime, 8)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 删除指定条件的记录
		/// </summary>
		/// <param name = "whereClause">自定义删除条件，where子句。如：id=1 and name='aaa'</param>
		/// <param name = "paras">where子句中定义的参数集合</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public int Delete(string whereClause, IEnumerable<DbParameter> paras, TransactionManager tm = null)
		{
			var sql = string.Format(@"DELETE FROM [dbo].[OperateLog] {0}", (string.IsNullOrEmpty(whereClause) ? string.Empty : " WHERE " + whereClause));
			return AdoBase(sql)
							.AddParameters(paras)
							.ExecuteNonQuery(tm);
		}
		#endregion

		#region  自定义方法集合
		#endregion

	}


	#endregion
}
